package main

import (
	"encoding/json"
	"fmt"
	"io"
	"net/http"
	"strings"
	"time"
)

// 内置的net/http包提供了http客户端和服务端的实现
func main() {
	url := "http://ark-proxy.dev.jiyujgt.com/fofund-boot-zztest"

	// 线程安全的，可复用
	client := &http.Client{
		Timeout: time.Second * 10,
	}

	// get请求
	res, err := client.Get(url + "/szt/dir")
	if err != nil {
		fmt.Println("请求失败: ", err)
		return
	}
	defer res.Body.Close()
	fmt.Println(res.StatusCode)
	body, err := io.ReadAll(res.Body)
	fmt.Println(string(body))

	// post请求
	dog := &Dog{
		Name: "傻狗",
		Age:  8,
	}
	json, _ := json.Marshal(dog)

	res, _ = client.Post(url+"/alarm/obj", "application/json", strings.NewReader(string(json)))
	defer res.Body.Close()
	fmt.Println(res.StatusCode)
	body, _ = io.ReadAll(res.Body)
	fmt.Println(string(body))

	//client.PostForm()
}

type Dog struct {
	Name string `json:"name"`
	Age  int    `json:"age"`
}
